<?php
session_start();
class Payment{
	var $unit;
	var $message;

	function connect(){
		$user="root";
		$password="";
		$database="whitehouse";
		mysql_connect(localhost,$user,$password);
		@mysql_select_db($database) or die( "Unable to select database");
	}

	function addPayment($details){
		$unit = $details['unit'];
		$amount = $details['amount'];
		$mode = $details['mode'];
		$date_received = $details['date_received'];
		$receipt_no = $details['receipt_no'];
		$query = "INSERT into payment(unit, amount, mode, date_received, receipt_no, date_entered) values ('$unit',$amount,'$mode','$date_received','$receipt_no',curdate())";
		mysql_query($query);
	}
	
	function getRequest($id){
		$query = "SELECT * from request where id = $id";
		$result = mysql_query($query);
		$row = mysql_fetch_array( $result );
		$request['id'] = $row['id'];
		$request['message'] = $row['message'];
		$request['date_sent'] = $row['date_sent'];
		$request['unit'] = $row['unit'];
		return $request;
	}
	
	function getList(){
		$query = "SELECT * from request";
		$result = mysql_query($query);
		$i=0;
		while($row = mysql_fetch_array( $result )){
		//	echo $row['unit']."<br />";
			//echo $row['id']."<br />";
			$list[$i]['id']=$row['id'];
			$list[$i]['unit']=$row['unit'];
			$i++;
		}
		return $list;
	}
	
	function deleteManyRequests($ids){
		for($i=0;$i<count($ids);$i++){
			$temp = $ids[$i];
			$query = "DELETE from request where id = $temp";
			mysql_query($query);
		}
	}
	function getPayments($unit){
		$query = "SELECT * from payment where unit = '$unit' order by date_received";
		$result = mysql_query($query)
		or die(mysql_error());
		$i=0;
		while($row = mysql_fetch_array($result)){

				$payments[$i]['date_received']=$row['date_received'];
				$payments[$i]['mode']=$row['mode'];
				$payments[$i]['receipt_no']=$row['receipt_no'];
				$payments[$i]['amount']=$row['amount'];
			$i++;
		}
		return $payments;
	}
}
?>